Ejercicio 1.
Para cada una de las siguientes funciones realiza la respectiva gráfica en el intervalo dado. Compara las gráficas de las derivadas aproximadas (con dos tamaños de paso \(h\neq 0\) y \(h=0\)) y la derivada exacta en tal intervalo. Realiza la gráfica del error de la derivada cuando \(h=0\).
graf1 <- function(f,i,d){
graf_f <- ggplot()+
geom_function(fun=f,xlim=c(i-.1,d+.1),color="dodgerblue",linewidth=.8)+
theme_bw()
graf_f
}graf2<-function(f,i,d,df){
x <<- seq(i,d,length.out=100)
df_h05 <<- fderiv(f,x,n=1,h=0.5,method=c("central"))
df_h01 <<- fderiv(f,x,n=1,h=0.1,method=c("central"))
df_h0 <<- fderiv(f,x,n=1,h=0,method=c("central"))
graf_df <- ggplot()+
geom_function(fun=df,xlim=c(i,d),color="firebrick",linewidth=1.2)+
geom_line(aes(x,df_h05),color="tomato2",linetype="dashed")+
geom_line(aes(x,df_h01),color="gold",linetype="dashed")+
geom_line(aes(x,df_h0),color="green",linetype="dashed")+
labs(y="Derivadas")+
theme_bw()
ggplotly(graf_df)
}graf3<-function(f){
error_derivada <- abs(df(x)-df_h0)
graf_error <- ggplot()+
geom_point(aes(x,error_derivada),color="deeppink",alpha=0.5)+
theme_bw()
graf_error
}- \(f(x)=e^{2x}-cos (2x)\), \(x\in [0,2]\)
f <- function(x){exp(2*x)-cos(2*x)}
df<-function(x) {2*exp(2*x) + 2*sin(2*x)}
i=0
d=2
graf1(f,i,d)graf2(f,i,d,df)graf3(f)- \(f(x)=log(x+2)-(x+1)^2\), \(x\in [0,5]\)
f <- function(x){log(x+2)-(x+1)^2}
df <- function(x) 1/(x+2) - 2*(x+1)
graf1(f,0,5)graf2(f,0,5,df)graf3(f)- \(f(x)=x\, sen\,x+x^2cos\,x\), \(x\in [0,\pi]\)
f <- function(x){x*sin(x)+x^2*cos(x)}
df <- function(x) sin(x) + x*cos(x) + 2*x*cos(x) - x^2*sin(x)
i=0
d=pi
graf1(f,i,d)graf2(f,i,d,df)graf3(f)- \(f(x)=(cos\,3x)^2-e^{2x}\), \(x\in [0,\pi/2]\)
f <- function(x){(cos(3*x))^2-exp(2*x)}
df <- function(x) -6*cos(3*x)*sin(3*x) - 2*exp(2*x)
i=0
d=pi/2
graf1(f,i,d)graf2(f,i,d,df)graf3(f)error_derivada <- abs(df(x)-df_h0)
graf_error <- ggplot()+
geom_line(aes(x,error_derivada),color="deeppink")+
theme_bw()
graf_error- \(f(x)=x\,cos\,x-x^2sen\,x\), \(x\in [0, 2\pi]\)
f <- function(x){x*cos(x)-x^2*sin(x)}
df <- function(x) cos(x) - x*sin(x) - 2*x*sin(x) - x^2*cos(x)
i=0
d=2*pi
graf1(f,i,d)graf2(f,i,d,df)graf3(f)- \(f(x)=2(log\,x)^2+3\,sen\,x\), \(x\in[1,5]\)
f <- function(x){2*log(x)^2+3*sin(x)}
df <- function(x) 4*log(x)/x + 3*cos(x)
i=1
d=5
graf1(f,i,d)graf2(f,i,d,df)graf3(f)Ejercicio 2
Da el valor aproximado (por medio de las funciones
integral y cotes, del package
pracma) y exacto (en caso de ser posible) de las siguientes
integrales (realiza la respectiva gráfica).
\[\begin{equation} \int_{0.5}^1 x^4 dx \end{equation}\]
f<-function(x){x^4}
x<-seq(.5,1,length.out=100)
graf_f <- ggplot()+
geom_function(fun=f,xlim=c(.5,1),color="dodgerblue",linewidth=.8)+
geom_area(aes(x,f(x)),fill="gold4",alpha=0.5)+
theme_bw()
graf_f\[\begin{equation} \int_{0}^{0.5} \frac{2}{x-4} dx \end{equation}\]
\[\begin{equation} \int_{1}^{1.5} x^2\, log(x) dx \end{equation}\]
\[\begin{equation} \int_{0}^{1} x^2 e^{-x}\,dx \end{equation}\]
\[\begin{equation} \int_{1}^{1.6} \frac{2x}{x^2-4} dx \end{equation}\]
\[\begin{equation} \int_{0}^{\pi/4} e^{3x}sin(2x) dx \end{equation}\]
\[\begin{equation} \int_{0}^{\pi/2} ((sen\,x)^2-2x\,sen\,x+1) dx \end{equation}\]